﻿#ifndef SEARCHFRIEND_H
#define SEARCHFRIEND_H

#include "httpclient.h"
#include "websocketclient.h"
#include "fileoperator.h"
#include "sqliteutil.h"
#include "searchfrienditem.h"
#include "searchitem.h"
#include "servicetype.h"
#include "applicationdialog.h"
#include "agreeapplicationdialog.h"
#include "applicationitem.h"
#include "orientation.h"

#include <QWidget>
#include <QMouseEvent>
#include <QScreen>
#include <QGraphicsDropShadowEffect>

namespace Ui {
class SearchFriend;
}

class SearchFriend : public QWidget
{
    Q_OBJECT

public:
     explicit SearchFriend(HttpClient *httpClient,FileOperator* fileOperator,SQLiteUtil* sQLiteUtil,const QString &email,const QString &username,QWidget *parent = nullptr);
    ~SearchFriend();
signals:
    void updateFriend(const QString &email,const QString &content,const QString &createTime);
    void closeClicked();
    void showTemporaryImage(QObject* sender,const QString &email,const QByteArray &data);
public slots:
    void updateApplication(const QString &email);
    void updateFriendList(const QString &email,const QString &username);
private slots:
    void showFriendInfo(const QString &email);
    void showApplicationList();

    void addFriend(const QString &email,const QString &username);
    void agreeFriend(const QString &email,const QString &username);
    void hideMask();

    void sendApplication(const QString &email,const QString &content,const QString &notename);
    void agreeApplication(const QString &email,const QString &notename);

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
private:
    Ui::SearchFriend *ui;
    bool isDragging=false;
    QPoint lastPos;
    HttpClient* httpClient;
    WebSocketClient* webSocketClient;
    FileOperator* fileOperator;
    SQLiteUtil* sQLiteUtil;
    ApplicationDialog* applicationDialog=nullptr;
    AgreeApplicationDialog* agreeApplicationDialog=nullptr;
    QString email;
    QString username;
    QString headImgUrl="/App/img?name=get_head_img";

    void createShadow();

    void insertFriendList(QWidget* widget,OrientType type);//插入好友项
    void insertSearchList(QWidget* widget,OrientType type);//插入搜索项
    void insertApplicationList(QWidget* widget,OrientType type);//插入申请项
    void loadFriendList();
    void loadHttpComponentRespond();
    void loadBaseComponentRespond();
    void clearSearchList();//清除搜索项
    void insertLabel(const QString &text,OrientType type);
    void friendItemClick(SearchFriendItem* newItem);
    void updateFriendListHImg(QString &email);
    void updateHeadImg(const QString &email);
    QByteArray toJson(QVariantMap &map);
    SearchItem* findSearchItem(const QString &email);
    ApplicationItem* findApplicationItem(const QString &email);
};

#endif // SEARCHFRIEND_H
